// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name:   CMPP30DeliverMessage.java

package com.haoxi.gateway.test.message;

import com.haoxi.gateway.test.CMPPConstant;
import com.haoxi.gateway.test.util.TypeConvert;
import java.util.Calendar;
import java.util.Date;

public class CMPP30DeliverMessage extends CMPPMessage {

    public CMPP30DeliverMessage(String Dest_Id, String Service_Id, int TP_pid,
            int TP_udhi, int Msg_Fmt, String Src_terminal_Id,
            int Src_terminal_type, int Registered_Delivery, byte[] Msg_Content,
            String LinkID)

    {
        int len = 109 + Msg_Content.length;
        buf = new byte[len];
        TypeConvert.int2byte(len, buf, 0);
        TypeConvert.int2byte(CMPPConstant.Deliver_Command_Id, buf, 4);
        setSequenceID();
        byte[] msgid = getMsgID1();
        System.arraycopy(msgid, 0, buf, 12, 8);
        System.arraycopy(Dest_Id.getBytes(), 0, buf, 20, Dest_Id.length());
        System
                .arraycopy(Service_Id.getBytes(), 0, buf, 41, Service_Id
                        .length());
        buf[51] = (byte) TP_pid;
        buf[52] = (byte) TP_udhi;
        buf[53] = (byte) Msg_Fmt;
        System.arraycopy(Src_terminal_Id.getBytes(), 0, buf, 54,
                Src_terminal_Id.length());
        buf[86] = (byte) Src_terminal_type;
        buf[87] = (byte) Registered_Delivery;
        buf[88] = (byte) Msg_Content.length;
        System.arraycopy(Msg_Content, 0, buf, 89, Msg_Content.length);
        System.arraycopy(LinkID.getBytes(), 0, buf, len - 20,
                LinkID.getBytes().length);

    }

    public int getMessageLength() {
        return TypeConvert.byte2int(buf, 0);
    }

    public int getCommandId() {
        return TypeConvert.byte2int(buf, 4);
    }

    public byte[] getMsgId() {
        byte tmpMsgId[] = new byte[8];
        System.arraycopy(buf, 12, tmpMsgId, 0, 8);
        return tmpMsgId;
    }

    public String getMsgIdStr() {
        byte tmpMsgId[] = new byte[8];
        System.arraycopy(buf, 12, tmpMsgId, 0, 8);
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < tmpMsgId.length; i++) {
            buffer.append(tmpMsgId[i]);
        }
        return buffer.toString();
    }

    public String getDestnationId() {
        byte tmpId[] = new byte[21];
        System.arraycopy(buf, 20, tmpId, 0, 21);
        String tmpStr = (new String(tmpId)).trim();
        if (tmpStr.indexOf(0) >= 0)
            return tmpStr.substring(0, tmpStr.indexOf(0));
        else
            return tmpStr;
    }

    public String getServiceId() {
        byte tmpId[] = new byte[10];
        System.arraycopy(buf, 41, tmpId, 0, 10);
        String tmpStr = (new String(tmpId)).trim();
        if (tmpStr.indexOf(0) >= 0)
            return tmpStr.substring(0, tmpStr.indexOf(0));
        else
            return tmpStr;
    }

    public int getTpPid() {
        int tmpId = buf[51];
        return tmpId;
    }

    public int getTpUdhi() {
        int tmpId = buf[52];
        return tmpId;
    }

    public int getMsgFmt() {
        int tmpFmt = buf[53];
        return tmpFmt;
    }

    public String getSrcterminalId() {
        byte tmpId[] = new byte[32];
        System.arraycopy(buf, 54, tmpId, 0, 32);
        String tmpStr = (new String(tmpId)).trim();
        if (tmpStr.indexOf(0) >= 0)
            return tmpStr.substring(0, tmpStr.indexOf(0));
        else
            return tmpStr;
    }

    public int getSrcterminalType() {
        int tmpFmt = buf[86];
        return tmpFmt;
    }

    public int getRegisteredDeliver() {
        return buf[87];
    }

    public int getMsgLength() {
        return buf[88] & 0xff;
    }

    public byte[] getMsgContent() {
        if (getRegisteredDeliver() == 0) {
            int len = getMsgLength();
            byte tmpContent[] = new byte[len];
            System.arraycopy(buf, 89, tmpContent, 0, len);
            return tmpContent;
        } else {
            return null;
        }
    }

    public String getLinkID() {
        int loc = 89 + getMsgLength();
        byte tmpReserve[] = new byte[20];
        System.arraycopy(buf, loc, tmpReserve, 0, 20);
        String tmpStr = (new String(tmpReserve)).trim();
        if (tmpStr.indexOf(0) >= 0)
            return tmpStr.substring(0, tmpStr.indexOf(0));
        else
            return tmpStr;
    }

    public byte[] getStatusMsgId() {
        if (getRegisteredDeliver() == 1) {
            byte tmpId[] = new byte[8];
            System.arraycopy(buf, 89, tmpId, 0, 8);
            return tmpId;
        } else {
            return null;
        }
    }

    public String getStatusMsgIdStr() {
        if (getRegisteredDeliver() == 1) {
            byte tmpId[] = new byte[8];
            System.arraycopy(buf, 89, tmpId, 0, 8);
            StringBuffer buffer = new StringBuffer();
            for (int i = 0; i < tmpId.length; i++) {
                buffer.append(tmpId[i]);
            }
            return buffer.toString();
        } else {
            return null;
        }
    }

    public String getStat() {
        if (getRegisteredDeliver() == 1) {
            byte tmpStat[] = new byte[7];
            System.arraycopy(buf, 97, tmpStat, 0, 7);
            return (new String(tmpStat)).trim();
        } else {
            return null;
        }
    }

    public Date getSubmitTime() {
        if (getRegisteredDeliver() == 1) {
            byte tmpbyte[] = new byte[2];
            System.arraycopy(buf, 104, tmpbyte, 0, 2);
            String tmpstr = new String(tmpbyte);
            int tmpYear = 2000 + Integer.parseInt(tmpstr);
            System.arraycopy(buf, 106, tmpbyte, 0, 2);
            tmpstr = new String(tmpbyte);
            int tmpMonth = Integer.parseInt(tmpstr) - 1;
            System.arraycopy(buf, 108, tmpbyte, 0, 2);
            tmpstr = new String(tmpbyte);
            int tmpDay = Integer.parseInt(tmpstr);
            System.arraycopy(buf, 110, tmpbyte, 0, 2);
            tmpstr = new String(tmpbyte);
            int tmpHour = Integer.parseInt(tmpstr);
            System.arraycopy(buf, 112, tmpbyte, 0, 2);
            tmpstr = new String(tmpbyte);
            int tmpMinute = Integer.parseInt(tmpstr);
            Calendar calendar = Calendar.getInstance();
            calendar.set(tmpYear, tmpMonth, tmpDay, tmpHour, tmpMinute);
            return calendar.getTime();
        } else {
            return null;
        }
    }

    public Date getDoneTime() {
        if (getRegisteredDeliver() == 1) {
            byte tmpbyte[] = new byte[2];
            System.arraycopy(buf, 114, tmpbyte, 0, 2);
            String tmpstr = new String(tmpbyte);
            int tmpYear = 2000 + Integer.parseInt(tmpstr);
            System.arraycopy(buf, 116, tmpbyte, 0, 2);
            tmpstr = new String(tmpbyte);
            int tmpMonth = Integer.parseInt(tmpstr) - 1;
            System.arraycopy(buf, 118, tmpbyte, 0, 2);
            tmpstr = new String(tmpbyte);
            int tmpDay = Integer.parseInt(tmpstr);
            System.arraycopy(buf, 120, tmpbyte, 0, 2);
            tmpstr = new String(tmpbyte);
            int tmpHour = Integer.parseInt(tmpstr);
            System.arraycopy(buf, 122, tmpbyte, 0, 2);
            tmpstr = new String(tmpbyte);
            int tmpMinute = Integer.parseInt(tmpstr);
            Calendar calendar = Calendar.getInstance();
            calendar.set(tmpYear, tmpMonth, tmpDay, tmpHour, tmpMinute);
            return calendar.getTime();
        } else {
            return null;
        }
    }

    public String getDestTerminalId() {
        if (getRegisteredDeliver() == 1) {
            byte tmpId[] = new byte[21];
            System.arraycopy(buf, 124, tmpId, 0, 21);
            return (new String(tmpId)).trim();
        } else {
            return null;
        }
    }

    public int getSMSCSequence() {
        if (getRegisteredDeliver() == 1) {
            int tmpSequence = TypeConvert.byte2int(buf, 145);
            return tmpSequence;
        } else {
            return -1;
        }
    }

    public String toString() {
        String tmpStr = "CMPP_Deliver: ";
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nMessageLength=")
                .append(getMessageLength())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nCommid=")
                .append(getCommandId())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nSequence_Id=")
                .append(getSequenceId())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nMsgIdStr=")
                .append(new String(getMsgIdStr()))));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nDestnationId=")
                .append(getDestnationId())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nServiceId=")
                .append(getServiceId())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nTpPid=").append(
                getTpPid())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nTpUdhi=")
                .append(getTpUdhi())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nMsgFmt=")
                .append(getMsgFmt())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nSrcterminalId=")
                .append(getSrcterminalId())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append(
                "\r\nSrcterminalType=").append(getSrcterminalType())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append(
                "\r\nRegisteredDeliver=").append(getRegisteredDeliver())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nMsgLength=")
                .append(getMsgLength())));
        if (getRegisteredDeliver() == 1) {
            tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                    .valueOf(String.valueOf(tmpStr))))
                    .append("\r\n--beginreport--")));
            tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                    .valueOf(String.valueOf(tmpStr)))).append(
                    "\r\nStatusMsgIdStr=").append(getStatusMsgIdStr())));
            tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                    .valueOf(String.valueOf(tmpStr)))).append("\r\nStat=")
                    .append(getStat())));
            tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                    .valueOf(String.valueOf(tmpStr))))
                    .append("\r\nSubmitTime=").append(getSubmitTime())));
            tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                    .valueOf(String.valueOf(tmpStr)))).append("\r\nDoneTime=")
                    .append(getDoneTime())));
            tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                    .valueOf(String.valueOf(tmpStr)))).append(
                    "\r\nDestTerminalId=").append(getDestTerminalId())));
            tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                    .valueOf(String.valueOf(tmpStr)))).append(
                    "\r\nSMSCSequence=").append(getSMSCSequence())));
            tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                    .valueOf(String.valueOf(tmpStr))))
                    .append("\r\n--endreport---")));
        } else {
            tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                    .valueOf(String.valueOf(tmpStr))))
                    .append("\r\nMsgContent=").append(
                            new String(getMsgContent()).trim())));
        }
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nLinkID=")
                .append(getLinkID())));
        return tmpStr;
    }

}
